
from .models import Poem

def getAllTitles():
    poem = Poem.objects.all()
    titles = [p.title for p in poem ]
    return titles 

def getPoemByTitle(timu):
    print("="*10, timu )
    p = Poem.objects.filter(title=timu)[0]
    d = {'title':p.title,
         'content':[ i for i in  p.content.split(' ')]}
    print(p.content)
    print(d)
    return d

def addPoem(title, content):
    # 添加诗歌到数据库 
    p = Poem()
    p.title = title.strip()
    p.content = content.strip() #
    p.save()